/*
 * TransLineBO.java
 *
 * Created on March 5, 2007, 8:07 PM
 */

package edu.byu.isys413.group1E.data;

/** Stores information about an employee's position
 *
 * @author Travis Kulbeth
 */
public class TransLineBO {
    
    private String txLineID;
    private RevenueSourceBO revSrc;
    private CouponBO coupon;
    private String transactionID;
    private double lineAmount = 0.0;        //for the convenience of calculation and access, I have added the lineAmount variable
    private double discountTaken = 0.0;     //as well as the discountTaken variable
    private int quantity;
    private String typeRS;
    boolean alreadyInDB;
    boolean isDirty;
    
    /** Creates a new instance of TransLineBO */
    public TransLineBO() {
    }
    
    /** Creates a new instance of TransLineBO using an ID
     *@param id contains the already existing id to be used for this object
     */
    public TransLineBO(String id){
        setTxLineID(id);
        setIsDirty(true);
    }
    
    /** Returns the Transaction Line ID
     * @return txLineID
     */
    public String getTxLineID() {
        return txLineID;
    }
    
    /** Sets the transaction line id
     *@param txLineID contains ID to be used for this transaction
     */
    public void setTxLineID(String txLineID) {
        setIsDirty(true);
        this.txLineID = txLineID;
    }
    
    /** Returns the revenue source id for this transaction line
     *@return revSrc
     */
    public RevenueSourceBO getRevSrc() {
        return this.revSrc;
    }
    
    /** Sets the revenue source id for this transaction line
     *@param revSrc contains the RevenueSourceBO to be used for this TxLine
     */
    public void setRevSrc(RevenueSourceBO revSrc) {
        setIsDirty(true);
        this.revSrc = revSrc;
    }
    
    /** Returns the couponID of the coupon applied (if a coupon is
     *applied to this transaction line)
     *
     *@return coupon
     */
    public CouponBO getCoupon() {
        return this.coupon;
    }
    
    /** Sets the couponID of the coupon that is applied
     *to this transaction line.
     *
     *@param coupon contains the coupon to be applied to this line
     */
    public void setCoupon(CouponBO coupon) {
        setIsDirty(true);
        this.coupon = coupon;
    }
    
    /** Returns the transactionID of the transaction that
     *this transaction line applies to.
     *
     *@return transactionID
     */
    public String getTransactionID() {
        return transactionID;
    }
    
    /** Sets the transactionID of the transaction that this
     *transaction applies to.
     *
     *@param transactionID contains the id for the current transaction
     */
    public void setTransactionID(String transactionID) {
        setIsDirty(true);
        this.transactionID = transactionID;
    }
    
    /** Returns the amount for this transaction line
     * (can be affected by the coupon applied).
     *@return lineAmount
     */
    public double getLineAmount() {
        return lineAmount;
    }
    
    /** Sets the amount for this transaction line.
     *@param lineAmount contains total amount for this line
     */
    public void setLineAmount(double lineAmount) {
        setIsDirty(true);
        this.lineAmount = lineAmount;
    }
    
    /** Calculates the line amount
     */
    public void calcLineAmount(){
        setIsDirty(true);
        //if there is a coupon to apply
        if(this.coupon != null){
            if(this.getCoupon().getCoupAmount() != 0.0){
                this.lineAmount = this.getRevSrc().getPrice() - this.getCoupon().getCoupAmount();
                this.setDiscountTaken(this.getCoupon().getCoupAmount());
            }else{
                this.lineAmount = this.getRevSrc().getPrice() - (this.getRevSrc().getPrice() * this.getCoupon().getCoupPercent());
                this.setDiscountTaken(this.getRevSrc().getPrice() * this.getCoupon().getCoupPercent());
            }
        }else{  //if no coupon
            this.lineAmount = this.getRevSrc().getPrice();
        }
    }
    
    /** Sets the alreadyInDB variable to indicate that
     * the information contained in this object has been stored in the database
     *@param is indicates whether the object is in the DB
     */
    public void setAlreadyInDB(boolean is){
        setIsDirty(true);
        this.alreadyInDB = is;
    }
    
    /** Returns if the information contained in this object has already been stored in the database
     *@return if object info was already written to DB.
     */
    public boolean isAlreadyInDB() {
        return alreadyInDB;
    }
    
    /** Returns if information has been changed within this object
     *@return if information has changed
     */
    public boolean isIsDirty() {
        return isDirty;
    }
    
    /** Sets the variable isDirty to indicate that some information has been modified or changed
     *in this object
     *@param isDirty indicates if info has changed
     */
    public void setIsDirty(boolean isDirty) {
        this.isDirty = isDirty;
    }

    /** Returns the variable discountTaken
     *@return discountTaken for this line
     */
    public double getDiscountTaken() {
        return discountTaken;
    }

    /** Sets the variable discountTaken
     *@param discountTaken contains the amount of discount for this line
     */
    public void setDiscountTaken(double discountTaken) {
        setIsDirty(true);
        this.discountTaken = discountTaken;
    }   

    /** Returns the RevenueSource type
     * 
     * @return typeRS
     */
    public String getTypeRS() {
        return typeRS;
    }

    /** Sets the RevenueSource type for this Tx Line
     * 
     * @param typeRS contains the RevenueSource type for this Tx Line
     */
    public void setTypeRS(String typeRS) {
        this.typeRS = typeRS;
        setIsDirty(true);
    }
       
}
